package main;


import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionReader;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

@Component
public class App {

	public static void main(String[] args) {
		// 1
		ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

		var dog = ctx.getBean("dog");

		System.out.println(dog);

		// 2
		Resource resource = new ClassPathResource("applicationContext.xml");
		BeanFactory fa = new DefaultListableBeanFactory();
		BeanDefinitionReader bdr = new XmlBeanDefinitionReader((BeanDefinitionRegistry) fa);
		bdr.loadBeanDefinitions(resource);

		var dog01 = fa.getBean("dog");

		System.out.println(dog01);

		System.out.println(fa.getBean("people"));

		((AbstractApplicationContext) ctx).close();

	}

}
